#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
	ll n;
	cin >> n;
	ll mx = LLONG_MIN;
	ll mi = LLONG_MAX;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		mx = max(a, mx);
		mi = min(a, mi);
	}
	cout << mx - mi << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t; cin >> t; while (t-- > 0) solve();
	return 0;
}